<?php
/**[文档类型控制器]
 * @Author: 976123967@qq.com
 * @Date:   2014-11-08 15:01:39
 * @Last Modified by:   Administrator
 * @Last Modified time: 2014-12-26 15:00:34
 */
class TypeAction extends PublicAction{

		/**
		 * [_initialize 初始化]
		 * @return [type] [description]
		 */
		public function _initialize()
		{
			parent::_initialize();
			$this->model = D('Type');
		}


		/**
		 * [index 文档类型列表]
		 * @return [type] [description]
		 */
		public function index()
		{
			$type = $this->model->get_type_all();
			$this->assign('data',$type);
			$this->display();
		}

		/**
		 * [add 添加文档类型列表]
		 */
		public function add()
		{
			if(IS_POST)
			{
				if(!$this->model->create()) $this->error($this->model->getError());
				$this->model->add_type();
				$this->success('类型添加成功',U('Type/index'));
				die;
			}
			$this->display();
		}

		/**
		 * [edit 编辑]
		 * @return [type] [description]
		 */
		public function edit()
		{
			if(IS_POST)
			{
				if(!$this->model->create()) $this->error($this->model->getError());
				$this->model->edit_type();
				$this->success('类型编辑成功',U('Type/index'));
				die;
			}
			$typeid = I('get.typeid',null,'intval');
			$field = $this->model->find_one($typeid);
			$this->assign('field',$field);
			$this->display();
		}


	/**
	 * [del 删除文档类型]
	 * @return [type] [description]
	 */
	public function del()
	{
		$typeid = I('typeid',null,'intval');
		if(!$this->model->delete_type($typeid)) $this->error($this->model->getError());
		$this->success('类型删除成功',U('Type/index'));
				die;
	}

	/**
	 * [update_cache 更新缓存]
	 * @return [type] [description]
	 */
	public function update_cache()
	{

		$this->model->update_cache();
		$this->success('缓存更新成功',U('Type/index'));
	}


	/**
	 * [update 更新缓存]
	 * @return [type] [description]
	 */
	public function update()
	{
		switch (true) {
			case isset($_POST['del_check']):
				if(!$this->model->delete_check())
					$this->error($this->model->getError(),$url);
				$this->success('删除成功',$url);
				break;
		}
	}


	/**
	 * [ajax_check_typename 验证类型名称是不是重复]
	 * @return [type] [description]
	 */
/*	public function ajax_check_typename()
	{
		$typename = I('post.typename');
		if(!$this->model->check_typename($typename))
			echo 0;
		else
			echo 1;
		die;
	}*/


}